package com.atguigu.gulimall.product.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.gulimall.product.vo.SocialUser;
import com.sun.deploy.net.HttpUtils;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class Oauth2Controller {

    @GetMapping("/oauth2.0/weibo/success")
    public String weibo(@RequestParam("code") String code){
        //通过code换取 AccessToken
        //使用 HttpUtils 工具类发送http请求
       // https://api.weibo.com/oauth2/access_token?client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=authorization_code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI&code=CODE
        //HttpUtils 返回值 response中获取
        //转换成json格式的字符串
        String json = EntityUtils.toString(response.getEntity());
        //将json格式的字符串封装到Java实体类
        SocialUser socialUser = JSON.parseObject(json, SocialUser.class);
        //远程调用member服务接口   要么登录 要么注册
        //登录成功后  重定向到首页
    }
}
